Skip to content

[6.x] Add an augmenting hook to Fields - #16009

Open
marcorieser wants to merge 1 commit into
statamic:6.xfrom
marcorieser:augmenting-hook
Open

marcorieser wants to merge 1 commit into
statamic:6.xfrom
marcorieser:augmenting-hook

Conversation

@marcorieser

Copy link
Copy Markdown
Contributor

Adds an augmenting hook that runs before Fields::augment() and shallowAugment(), so an addon can change the field values that are about to be augmented.

I needed this to fill in default values that depend on sibling fields when a Replicator, Grid or Bard set is read, without extending those fieldtypes.

Fields::hook('augmenting', function ($payload, $next) {
    // $payload->fields is the Fields being augmented, $payload->shallow says which kind of augmentation it is
    $payload->fields = ...;

    return $next($payload);
});

It runs for the fields of Replicator, Grid and Bard sets and rows. Top-level fields on entries, terms and the like don't go through Fields::augment(), so it doesn't fire for them.

Includes a test.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant